package com.maple.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.maple.admin.common.util.AjaxJson;
import com.maple.admin.domain.entity.Order;
import com.maple.admin.domain.entity.ProductOne;
import com.maple.admin.domain.entity.Shop;
import com.maple.admin.service.ProductOneService;
import com.maple.admin.service.ShopService;
import io.swagger.annotations.Api;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/shop")
@Api(value = "shop", tags = "购物车模块")
public class ShopController {

    @Resource
    private ShopService shopService;

    @Resource
    private ProductOneService productOneService;

    @GetMapping("/list")
    public AjaxJson selectAll(){

        return  AjaxJson.getSuccessData(shopService.list());
    }
    @PostMapping("/save")
        public AjaxJson saveShop(@RequestBody Shop shop){

        ProductOne productOne = productOneService.getById(shop.getPid());
        if (productOne==null){
            return AjaxJson.getError("商品不存在");
        }

            return AjaxJson.getSuccessData(shopService.saveOrUpdate(shop));

    }
    @GetMapping("/delete/{sid}")
    @Transactional
    public AjaxJson delete(@PathVariable Integer sid){

       /* QueryWrapper wrapper  = new QueryWrapper<>();
        wrapper.eq("sid",sid);
        applyService.remove(wrapper);
        detailService.remove(wrapper);*/

        return AjaxJson.getSuccessData(shopService.removeById(sid));
    }
}
